package com.puyuba.puyuba.view.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.puyuba.puyuba.ConstantValues;
import com.puyuba.puyuba.network.BaseApis;
import com.pyb.java.cache.CacheUserInfo;
import com.pyb.java.commonutil.activity.ActivityManager;
import com.pyb.java.commonutil.constant.RouterFragmentPath;
import com.pyb.java.commonutil.utils.StatusBarUtil;
import com.pyb.module.live.fragment.HomeLiveFragment;

/**
 * 统一管理主页Fragment的获取
 */

public class HomeTabManager {
    private static HomeTabManager instance;
    private Bundle mBundle;

    private HomeLiveFragment homePageFragment;
    private MyFragment mMyFragment;
    //    private WebviewFragmentFind webviewFragment;
    private FragmentNative mFindFragment;
    private LearnRegistrationFragment mLearnFragment;
    private MessageFragment mMessageFragment;

    private HomeTabManager() {
        //no instance
    }

    public static HomeTabManager getInstance() {
        if (instance == null) {
            synchronized (HomeTabManager.class) {
                instance = new HomeTabManager();
            }
        }
        return instance;
    }

    public Fragment getFragmentByIndex(int index) {
//        if (index == ConstantValues.WECHAT_INDEX) {
//            StatusBarUtil.setDarkMode(ActivityManager.last());
//        } else {
//            StatusBarUtil.setLightMode(ActivityManager.last());
//        }
        StatusBarUtil.setLightMode(ActivityManager.last());
        Fragment fragment = null;
        switch (index) {
            //考友圈
//            case ConstantValues.WECHAT_INDEX:
//                if (homePageFragment == null) {
//                    homePageFragment = (HomeLiveFragment) ARouter.getInstance().
//                            build(RouterFragmentPath.Live.PAGER_HOME_LIVE_FM).navigation();
//                }
//                fragment = homePageFragment;
//                break;
            //发现
            case ConstantValues.FIND_INDEX:
                if (mFindFragment == null) mFindFragment = new FragmentNative();
                fragment = mFindFragment;
                break;
            //报名
            case ConstantValues.SIGNUP_INDEX:
                if (mLearnFragment == null) {
                    mLearnFragment = new LearnRegistrationFragment();
                }
                fragment = mLearnFragment;
                break;
            //消息
            case ConstantValues.MESSAGE_INDEX:
                if (mMessageFragment == null) {
                    mMessageFragment = new MessageFragment();
                }
                fragment = mMessageFragment;
                break;
            //我的
            case ConstantValues.ME_INDEX:
                if (mMyFragment == null) {
                    mMyFragment = new MyFragment();
                }
                fragment = mMyFragment;
                break;
        }

        if (fragment != null) {
            if (mBundle != null) {
                fragment.setArguments(mBundle);
            }
        }
        return fragment;
    }
}
